package lol.clann.minecraft.springboot.plugin.bukkit.impl;

import lol.clann.minecraft.springboot.api.bukkit.utils.PlayerUtils;
import lol.clann.minecraft.springboot.bukkit.utils.BukkitUtils;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.entity.Player;

/**
 *
 * @author pyz
 * @date 2019/5/2 5:28 PM
 */
@Slf4j
public abstract class PlayerUtilsImpl implements PlayerUtils {
    private boolean supportTitle;

    protected void init() throws NoSuchFieldException {
        try {
            Player.class.getMethod("sendTitle", new Class[]{String.class, String.class, int.class, int.class, int.class});
            supportTitle = true;
        } catch (Throwable e) {
            supportTitle = false;
        }
        LOGGER.info("supportTitle=" + supportTitle);
    }

    @Override
    public void sendTitle(Player player, String title, String subtitle, int fadeIn, int stay, int fadeOut) {
        if (BukkitUtils.getBukkitVersionNumber() < 10800) {
            return;
        }
        player.sendTitle(title, subtitle, fadeIn, stay, fadeOut);
    }

}
